package com.dnfm.game.equip.service;


import com.dnfm.game.equip.model.MonsterAttribute;
import com.dnfm.game.equip.model.RoleAttribute;
import com.dnfm.game.equip.pojo.EquipAttribute;

import java.util.List;

public class DamageService {


    public static Double computeAttack(EquipAttribute attribute) {
        Double baseAct = attribute.getBaseAttack();
        Double actRate = attribute.getAttackRate();
        Double fixAct = attribute.getFixedAttack();
        return baseAct * (1 + actRate) + fixAct;
    }

    public static Double computePower(EquipAttribute attribute) {
        Double basePower = attribute.getBasePower();
        Double powerRate = attribute.getPowerRate();
        return basePower * (1 + powerRate) / 250 + 1;
    }

    public static Double computeDamageIncrease(EquipAttribute attribute) {
        return 1 + attribute.getDamageIncrease();
    }

    public static Double computeAttributeEnhanced(EquipAttribute attribute) {
        return 1.05 + attribute.getAttributeEnhanced() * 0.0045;
    }

    public static Double computeAdditive(EquipAttribute attribute) {
        Double damageAdditive = attribute.getDamageAdditive();
        Double attributeAdditive = attribute.getAttributeAdditive();
        Double attributeEnhanced = attribute.getAttributeEnhanced();
        return 1 + 1.015 * (damageAdditive + attributeAdditive * (1.05 + attributeEnhanced * 0.0045));
    }

    public static Double computeCriticalStrikeDamage(EquipAttribute attribute) {
        Double criticalStrikeDamageIncrease = attribute.getCriticalStrikeDamageIncrease();
        return 1 + (0.5 + criticalStrikeDamageIncrease);
    }

    public static Double computeCriticalStrikeDamageWithRate(EquipAttribute attribute, Double strikeRate) {
        Double criticalStrikeDamageIncrease = attribute.getCriticalStrikeDamageIncrease();
        return 1 + (0.5 + criticalStrikeDamageIncrease) * strikeRate;
    }

    public static Double computeCriticalStrikeRate(EquipAttribute attribute, Double monsterLevel) {
        Double strikeRate = attribute.getCriticalStrikeRate();
        Double strike = attribute.getCriticalStrike();
        return strikeRate + strike * 0.0097 / (3.75 * Math.pow(1.25, monsterLevel / 8));
    }


    public static Double computeSkillIncrease(EquipAttribute attribute) {
        Double equipSkillIncrease = attribute.getEquipSkillIncrease();
        Double passiveSkillIncrease = attribute.getPassiveSkillIncrease();
        Double chargeSkillIncrease = attribute.getChargeSkillIncrease();
        Double activeBuffSkillIncrease = attribute.getActiveBuffSkillIncrease();
        return (1 + activeBuffSkillIncrease + chargeSkillIncrease) *
                (equipSkillIncrease + passiveSkillIncrease) *
                (1 + attribute.getTpSkillIncrease());
    }


    public static Double computeDefense(EquipAttribute attribute, RoleAttribute roleAttribute, MonsterAttribute monsterAttribute) {
        Double decreaseDefense = attribute.getDecreaseDefense();
        double realDefense = monsterAttribute.getMonsterDefense() - decreaseDefense;
        return (1 - realDefense / (realDefense + roleAttribute.getRoleLevel() * 200)) * monsterAttribute.getDefenseRate();

    }


    public static EquipAttribute computePanel(List<EquipAttribute> list) {
        EquipAttribute equ = new EquipAttribute();
        for (EquipAttribute attribute : list) {
            equ.setBasePower(equ.getBasePower() + attribute.getBasePower());
            equ.setBaseAttack(equ.getBaseAttack() + attribute.getBaseAttack());
            equ.setFixedAttack(equ.getFixedAttack() + attribute.getFixedAttack());
            equ.setPowerRate(equ.getPowerRate() + attribute.getPowerRate());
            equ.setAttackRate(equ.getAttackRate() + attribute.getAttackRate());
            equ.setDamageIncrease(equ.getDamageIncrease() + attribute.getDamageIncrease());
            equ.setDamageAdditive(equ.getDamageAdditive() + attribute.getDamageAdditive());
            equ.setAttributeEnhanced(equ.getAttributeEnhanced() + attribute.getAttributeEnhanced());
            equ.setAttributeAdditive(equ.getAttributeAdditive() + attribute.getAttributeAdditive());
            equ.setDecreaseDefense(equ.getDecreaseDefense() + attribute.getDecreaseDefense());
            equ.setCriticalStrike(equ.getCriticalStrike() + attribute.getCriticalStrike());
            equ.setCriticalStrikeRate(equ.getCriticalStrikeRate() + attribute.getCriticalStrikeRate());
            equ.setCriticalStrikeDamageIncrease(equ.getCriticalStrikeDamageIncrease() + attribute.getCriticalStrikeDamageIncrease());
            equ.setHit(equ.getHit() + attribute.getHit());
            equ.setHitRate(equ.getHitRate() + attribute.getHitRate());
            equ.setPassiveSkillIncrease(equ.getPassiveSkillIncrease() + attribute.getPassiveSkillIncrease());
            equ.setActiveBuffSkillIncrease(equ.getActiveBuffSkillIncrease() + attribute.getActiveBuffSkillIncrease());
            equ.setChargeSkillIncrease(equ.getChargeSkillIncrease() + attribute.getChargeSkillIncrease());
            equ.setTpSkillIncrease(equ.getTpSkillIncrease() + attribute.getTpSkillIncrease());
            equ.setEquipSkillIncrease((equ.getEquipSkillIncrease() == 0 ? 1 : equ.getEquipSkillIncrease()) * (1 + attribute.getEquipSkillIncrease()));
        }


        return equ;
    }


}
